<template>
  <a-popover v-model:open="visible" title="图标" trigger="click">
    <template #content>
      <div class="icon-box">
        <div
          v-for="(item, index) in iconArr"
          :key="index"
          @click="handleClick(item)"
          class="icon-content"
        >
          <component :is="$antIcons[item]" />
        </div>
      </div>
    </template>
    <a-button type="primary"><AppstoreOutlined /></a-button>
  </a-popover>
</template>

<script setup>
import { ref } from "vue";
import { AppstoreOutlined } from "@ant-design/icons-vue";
import icons from "./icon.json";
const iconArr = ref(icons);
const visible = ref(false);

const emits = defineEmits('onChooseIcon')
const handleClick = (icon) => {
  emits('onChooseIcon',icon)
  visible.value = false;
};
</script>

<style scoped>
.icon-box {
  overflow: auto;
  font-size: 20px;
  width: 250px;
  height: 230px;
  display: flex;
  flex-wrap: wrap;
  flex-direction: row;
  align-content: flex-start;
  justify-content: center;
}

.icon-content {
  width: 45px;
  height: 40px;
  margin: 5px;
  cursor: pointer;
  text-align: center;
  border-radius: 6px;
  border: 1px solid #ccc;
}

.icon-content:hover {
  background: #1890ff;
}
</style>
